package com.example.ck.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.ck.dao.LaboratoryDao;
import com.example.ck.entity.Laboratory;
import com.example.ck.service.LaboratoryService;
import com.example.ck.utils.JsonConvertUtils;
import com.fasterxml.jackson.core.JsonProcessingException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;


/**
 * 实验室类型表(Laboratory)表服务实现类
 *
 * @author makejava
 * @since 2024-05-01 12:14:45
 */

@Slf4j
@Service("laboratoryService")
public class LaboratoryServiceImpl implements LaboratoryService {
    @Autowired
    private LaboratoryDao laboratoryDao;

    /**
     * 查询所有实验室
     *
     * @return
     */
    @Override
    public List<Laboratory> getAllLaboratory() {
        List<Laboratory> laboratories = laboratoryDao.selectList(null);
        return laboratories;
    }

    /**
     * 添加实验室
     *
     * @param laboratory
     * @return
     */
    @Override
    public boolean addLaboratory(Laboratory laboratory) {
        int i = laboratoryDao.insert(laboratory);
        return i > 0;
    }

    /**
     * 在指定实验室中添加实验室类型
     *
     * @param laboratoryName
     * @return
     */
    @Override
    public boolean addLaboratoryToLaboratory(String laboratoryName,String laboratoryType){
        QueryWrapper qw = new QueryWrapper<>();
        qw.eq("laboratory_name", laboratoryName);
        Laboratory laboratory = laboratoryDao.selectOne(qw);
        laboratory.setLaboratoryType(laboratoryType);
        return laboratoryDao.updateById(laboratory) > 0;
    }


    /**
     * 根据实验室名称删除实验室
     *
     * @param laboratoryName
     * @return
     */
    @Override
    public boolean deleteLaboratory(String laboratoryName) {
        QueryWrapper qw = new QueryWrapper<>();
        qw.eq("laboratory_name", laboratoryName);
        int i = laboratoryDao.delete(qw);
        return i > 0;
    }

    /**
     * 根据实验室名称和实验室类型删除实验室类型
     *
     * @param laboratoryName
     * @param laboratoryType
     * @return
     */
    @Override
    public boolean deleteLaboratoryType(String laboratoryName, String laboratoryType) {
        QueryWrapper qw = new QueryWrapper<>();
        qw.eq("laboratory_name", laboratoryName);
        Laboratory laboratory = laboratoryDao.selectOne(qw);
        laboratory.setLaboratoryType(laboratoryType);
        return laboratoryDao.updateById(laboratory) > 0;
    }
}
